package com.gzs.learn.payment.pay;

import com.gzs.learn.inf.BaseResponseDto;
import com.gzs.learn.payment.pay.action.ActionInvoker;
import com.gzs.learn.payment.pay.validate.ValidateInvoker;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
public class PaymentDomain {
    private final ValidateInvoker validateInvoker;
    private final ActionInvoker actionInvoker;

    public BaseResponseDto<?> execute(PaymentContext<ContextBase> paymentContext) {
        BaseResponseDto<? extends Object> validateResult = validateInvoker.invoke(paymentContext);
        if (!BaseResponseDto.isSuccess(validateResult)) {
            // 参数校验不合法
            return validateResult;
        }

        return actionInvoker.invoke(paymentContext);
    }
}
